/* 
	PROGRAM: Thanatos
	AUTHOR: Dwyer, Patrick; Easton, Sean; Roy, Bobby 
	FSU GARNET ID: pmd04; sde07; rcr05e
	COURSE INFORMATION: CNT5412
	Due Date: 04/19/2011
	
	SUMMARY 
		The implementation of the Node class
*/

#include "Node.h"
#include <iostream>

using namespace std;

Node::Node()
{
  // zero out m_address
  bzero((void *) &m_address, sizeof (struct sockaddr_in));
  m_address.sin_family = AF_INET;

  // default socket is STDIN
  m_socketDesc = 0;
}

Node::Node(string ip, string port) : m_ipAddress(ip), m_portNum(port)
{

}

Node::Node(struct sockaddr_in address, vector<Node*> peers):
m_address(address), m_peers(peers)
{
    //TODO
}

Node::Node(const Node& ref): 
m_address(ref.m_address), m_peers(ref.m_peers)
{
    //TODO

}

Node::~Node()
{
    //TODO
}

void Node::SetIP(string ip)
{
  // set ip address
  inet_pton(AF_INET, ip.c_str(), &(m_address.sin_addr));
}

void Node::SetPort(int p)
{
  // set port
  m_address.sin_port = htons(p);
}

bool operator==(const Node& lhs, const Node& rhs)
{
  if(lhs.m_address.sin_family != rhs.m_address.sin_family)
    return false;
  if(lhs.m_address.sin_port != rhs.m_address.sin_port)
    return false;
  if(lhs.m_address.sin_addr.s_addr != rhs.m_address.sin_addr.s_addr)
    return false;

  return true;
  //  return (lhs.m_address == rhs.m_address);
}
